package com.digitalchina.lxnsy.activity.old;

import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.digitalchina.lxnsy.R;
import com.digitalchina.lxnsy.api.BusinessCart;
import com.digitalchina.lxnsy.api.BusinessCollect;
import com.digitalchina.lxnsy.api.BusinessDataMall;
import com.digitalchina.lxnsy.api.BusinessEvaluate;
import com.digitalchina.lxnsy.base.BaseActivity;
import com.digitalchina.lxnsy.constant.Constant;
import com.digitalchina.lxnsy.constant.MSG;
import com.digitalchina.lxnsy.constant.URL;
import com.digitalchina.lxnsy.entity.DataMallVO;
import com.digitalchina.lxnsy.entity.EvaluateVO;
import com.digitalchina.lxnsy.entity.ScoreMap;
import com.digitalchina.lxnsy.toolkit.FastJsonUtil;
import com.digitalchina.lxnsy.toolkit.FrescoUtil;
import com.digitalchina.lxnsy.toolkit.GlideImageLoader;
import com.digitalchina.lxnsy.toolkit.GotoUtil;
import com.digitalchina.lxnsy.toolkit.StringUtil;
import com.digitalchina.lxnsy.toolkit.Utils;
import com.digitalchina.lxnsy.view.BadgeView;
import com.facebook.drawee.view.SimpleDraweeView;
import com.youth.banner.Banner;
import com.youth.banner.BannerConfig;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;


/**
 * ================================================
 * 项目名称：BigData
 * 类描述：
 * 包名：com.digitalchina.bigdata.activity
 * 创建人：郑皓
 * 创建时间：2016/12/29 11:30
 * 修改备注：
 * ================================================
 */
public class DataDetailActivity extends BaseActivity {


    @Bind(R.id.data_detail_banner)
    Banner dataDetailBanner;
    @Bind(R.id.data_detail_tv_title)
    TextView dataDetailTvTitle;
    @Bind(R.id.data_detail_tv_RMB_tag)
    TextView dataDetailTvRMBTag;
    @Bind(R.id.data_detail_tv_price)
    TextView dataDetailTvPrice;
    @Bind(R.id.data_detail_tv_type)
    TextView dataDetailTvType;
    @Bind(R.id.data_detail_tv_content)
    TextView dataDetailTvContent;
    @Bind(R.id.data_detail_tv_check_goods)
    TextView dataDetailTvCheckGoods;
    @Bind(R.id.data_detail_rl_goods_summary)
    RelativeLayout dataDetailRlGoodsSummary; // 查看商品详情
    @Bind(R.id.data_detail_tv_evaluate)
    TextView dataDetailTvEvaluate;
    @Bind(R.id.data_detail_rl_eva_list)
    RelativeLayout dataDetailRlEvaList; // 查看评论
    @Bind(R.id.data_detail_tv_grade)
    TextView dataDetailTvGrade;
    @Bind(R.id.data_detail_iv_star1)
    ImageView dataDetailIvStar1;
    @Bind(R.id.data_detail_iv_star2)
    ImageView dataDetailIvStar2;
    @Bind(R.id.data_detail_iv_star3)
    ImageView dataDetailIvStar3;
    @Bind(R.id.data_detail_iv_star4)
    ImageView dataDetailIvStar4;
    @Bind(R.id.data_detail_iv_star5)
    ImageView dataDetailIvStar5;
    @Bind(R.id.data_detail_tv_merchant)
    TextView dataDetailTvMerchant;
    @Bind(R.id.data_detail_sdv_merchant_logo)
    SimpleDraweeView dataDetailSdvMerchantLogo;
    @Bind(R.id.data_detail_tv_merchant_name)
    TextView dataDetailTvMerchantName;
    @Bind(R.id.data_detail_tv_merchant_grade)
    TextView dataDetailTvMerchantGrade;
    @Bind(R.id.data_detail_iv_lantern1)
    ImageView dataDetailIvLantern1;
    @Bind(R.id.data_detail_iv_lantern2)
    ImageView dataDetailIvLantern2;
    @Bind(R.id.data_detail_iv_lantern3)
    ImageView dataDetailIvLantern3;
    @Bind(R.id.data_detail_iv_lantern4)
    ImageView dataDetailIvLantern4;
    @Bind(R.id.data_detail_iv_lantern5)
    ImageView dataDetailIvLantern5;
    @Bind(R.id.data_detail_iv_chat)
    ImageView dataDetailIvChat;
    @Bind(R.id.item_evaluate_sdv_head)
    SimpleDraweeView itemEvaluateSdvHead;
    @Bind(R.id.item_evaluate_tv_name)
    TextView itemEvaluateTvName;
    @Bind(R.id.item_evaluate_tv_time)
    TextView itemEvaluateTvTime;
    @Bind(R.id.item_evaluate_iv_star1)
    ImageView itemEvaluateIvStar1;
    @Bind(R.id.item_evaluate_iv_star2)
    ImageView itemEvaluateIvStar2;
    @Bind(R.id.item_evaluate_iv_star3)
    ImageView itemEvaluateIvStar3;
    @Bind(R.id.item_evaluate_iv_star4)
    ImageView itemEvaluateIvStar4;
    @Bind(R.id.item_evaluate_iv_star5)
    ImageView itemEvaluateIvStar5;
    @Bind(R.id.item_evaluate_tv_content)
    TextView itemEvaluateTvContent;
    @Bind(R.id.data_detail_ll_goto_merchant_home)
    LinearLayout dataDetailLlGotoMerchantHome;
    @Bind(R.id.data_detail_ll_collect_merchants)
    LinearLayout dataDetailLlCollectMerchants;
    //底部导航栏
    @Bind(R.id.detail_bottom_iv_collect)
    ImageView detailBottomIvCollect;
    @Bind(R.id.detail_bottom_ll_collect)
    LinearLayout detailBottomLlCollect;
    @Bind(R.id.detail_bottom_ll_share)
    LinearLayout detailBottomLlShare;
    @Bind(R.id.detail_bottom_iv_shop_cart)
    ImageView detailBottomIvShopCart;
    @Bind(R.id.detail_bottom_ll_shop_cart)
    LinearLayout detailBottomLlShopCart;
    @Bind(R.id.detail_bottom_tv_add_cart)
    TextView detailBottomTvAddCart;
    @Bind(R.id.detail_bottom_tv_buy_now)
    TextView detailBottomTvBuyNow;
    @Bind(R.id.view_line_evaluate)
    View viewLineEvaluate; // 评论线条
    @Bind(R.id.item_evaluate_layout)
    RelativeLayout itemEvaluateLayout; // 第一条评论布局

    private DataMallVO dataMallVO;
    private ScoreMap scoreMap;

    private int msgWhat;//返回标识
    private boolean isCollected = false;//默认商品没有收藏
    private boolean isMerchantsCollected = false;//默认商户没有收藏
    private String collectType = ""; // 收藏类型

    private String productId; // 商品id
    private String[] evaCountArray = new String[]{};

    private List<EvaluateVO> evaluateVOList; // 评论列表

    @Override
    public void setLayout() {
        setContentLayout(R.layout.activity_data_detail);
        setTitle("数据详情");
    }

    @Override
    public void initMember() {

//        if (getIntent().hasExtra("DataMallVO")) { // 来自列表
//            dataMallVO = (DataMallVO) getIntent().getSerializableExtra("DataMallVO");
//            getEva();
//            isCollect();
//            initBanner();
//            setContent();
//        }
        if (getIntent().hasExtra("productId")) {
            productId = getIntent().getStringExtra("productId");
            BusinessDataMall.productdetails(this, productId, mHandler);
        }

//        Uri uri = Uri.parse("http://help.baidu.com/resources/images/logo2x.png");
//        dataDetailSdvMerchantLogo.setImageURI(uri);
    }

    /**
     * 获取最新一条评价
     */
    private void getEva() {
        BusinessEvaluate.findProductEvalutionList(this, dataMallVO.getId(), "0", "1", "1", mHandler);
        BusinessEvaluate.findProductEvalutionTypeCount(this, dataMallVO.getId(), mHandler);
    }

    @Override
    protected void onResume() {
        super.onResume();
        getCartNum();
    }

    /**
     * 内容填充
     */
    private void setContent() {
        dataDetailTvTitle.setText(dataMallVO.getTitle());
        dataDetailTvPrice.setText(dataMallVO.getAmount_num());
        dataDetailTvType.setText(dataMallVO.getResourceType());
        dataDetailTvContent.setText(dataMallVO.getIntroduce());

        if (dataMallVO.getMerchant() == null)
            return;
        FrescoUtil.showImageSmall(dataMallVO.getMerchant().getHeadPortrait() != null ? dataMallVO.getMerchant().getHeadPortrait() : "", dataDetailSdvMerchantLogo);
        dataDetailTvMerchantName.setText(dataMallVO.getMerchant().getMerchantName());
        if (scoreMap != null) {
            String avg = scoreMap.getAverageScore();
            if (StringUtil.isStrEmpty(avg) || StringUtil.isStrEqual(avg, "0")) {
                setMerchantScore("3.0");
            } else if (Double.parseDouble(avg) > 5) {
                setMerchantScore("5.0");
            } else {
                setMerchantScore(avg + ".0");
            }
        }

        int creditLevel = dataMallVO.getMerchant().getCreditLevel();
        if (creditLevel < 400)
            setMerchantLevel("1.0");// 商户等级
        else if (400 <= creditLevel && creditLevel < 1600)
            setMerchantLevel("2.0");// 商户等级
        else if (1600 <= creditLevel && creditLevel < 3600)
            setMerchantLevel("3.0");// 商户等级
        else if (3600 <= creditLevel && creditLevel < 6400)
            setMerchantLevel("4.0");// 商户等级
        else if (6400 <= creditLevel)
            setMerchantLevel("5.0");// 商户等级
    }

    /**
     * 设置商户分数
     */
    private void setMerchantScore(String score) {
        dataDetailTvMerchantGrade.setText(score);
    }

    /**
     * 设置顶部轮播图
     */
    private void initBanner() {
        List<String> imagesList = new ArrayList<>();

        if (dataMallVO.getProductImageList() == null)
            return;

        for (int i = 0; i < dataMallVO.getProductImageList().size(); i++) {
            imagesList.add(Utils.imageUrl(dataMallVO.getProductImageList().get(i).getImageName()));
        }

//        String[] urls = getResources().getStringArray(R.array.url);
        String[] tips = getResources().getStringArray(R.array.title);
//        List<String> list = Arrays.asList(urls);
//        List<?> images = new ArrayList<>(list);
        List<String> list1 = Arrays.asList(tips);
        List<String> titles = new ArrayList<>(list1);

        //设置图片加载器
        dataDetailBanner.setImageLoader(new GlideImageLoader(1));
        //设置图片集合
        dataDetailBanner.setImages(imagesList);
        //设置标题
        dataDetailBanner.setBannerTitles(titles);
        //设置风格
        dataDetailBanner.setBannerStyle(BannerConfig.NUM_INDICATOR);
        //banner设置方法全部调用完毕时最后调用
        dataDetailBanner.start();
    }

    @Override
    public void addListener() {
    }


    @Override
    public void setHandler() {
        mHandler = new Handler() {
            @Override
            public void handleMessage(Message msg) {
                super.handleMessage(msg);
                msgWhat = msg.what;
                switch (msg.what) {
                    case MSG.MSG_IS_STORE_SUCCESS://是否已经收藏
                        String isCollect = FastJsonUtil.getString(msg.obj.toString(), "data");
                        setCollectImg(isCollect);
                        break;
                    case MSG.MSG_IS_STORE_FIELD:
                        showToast(msg.obj.toString());
                        break;
                    case MSG.MSG_CANCEL_STORE_SUCCESS:// 取消收藏
                        setCollectImg("false");
                        showToast("取消收藏");
                        break;
                    case MSG.MSG_CANCEL_STORE_FIELD:
                        showToast(msg.obj.toString());
                        break;
                    case MSG.MSG_STORE_SUCCESS: // 收藏
                        if (!StringUtil.isStrEmpty(collectType) && collectType.equals(Constant.STORE_GOODS)) {
                            setCollectImg("true");
                        }
                        if (!StringUtil.isStrEmpty(collectType) && collectType.equals(Constant.STORE_MERCHANTS)) {
                            isMerchantsCollected = true;
                        }
                        showToast("收藏成功");
                        break;
                    case MSG.MSG_STORE_FIELD:
                        showToast(msg.obj.toString());
                        break;
                    case MSG.MSG_GET_SHOPPING_CART_ITEM_COUNT_SUCCESS: // 购物车数量
                        String cartCount = FastJsonUtil.getBean(msg.obj.toString(), "body", "itemCount", String.class);
                        setBadgeView(Integer.parseInt(cartCount));
                        break;
                    case MSG.MSG_GET_SHOPPING_CART_ITEM_COUNT_FIELD:
                        showToast(msg.obj.toString());
                        break;
                    case MSG.MSG_ADD_SHOPPING_CART_ITEM_SUCCESS: // 加入购物车
                        getCartNum();
                        break;
                    case MSG.MSG_ADD_SHOPPING_CART_ITEM_FIELD:
                        showToast(msg.obj.toString());
                        break;
                    case MSG.MSG_PRODUCT_DETAILS_SUCCESS: // 商品详情
                        callBack(msg.obj);
                        break;
                    case MSG.MSG_PRODUCT_DETAILS_FIELD:
                        showToast(msg.obj.toString());
                        break;
                    case MSG.MSG_FIND_PRODUCT_EVALUTION_LIST_SUCCESS: // 评论列表
                        callBack(msg.obj);
                        break;
                    case MSG.MSG_FIND_PRODUCT_EVALUTION_LIST_FIELD:
                        setItemEvaData(new ArrayList<EvaluateVO>());
                        showToast(msg.obj.toString());
                        break;
                    case MSG.MSG_EVALUATION_TYPE_COUNT_SUCCESS: // 个评论个数
                        callBack(msg.obj);
                        break;
                    case MSG.MSG_EVALUATION_TYPE_COUNT_FIELD:
                        setEvaData(new String[]{});
                        showToast(msg.obj.toString());
                        break;
                }
            }
        };
    }

    /**
     * 设置购物车数量提示
     */
    BadgeView badgeView;

    private void setBadgeView(int count) {
        if (null == badgeView)
            badgeView = new BadgeView(this);
        badgeView.setTargetView(detailBottomLlShopCart);
        badgeView.setBadgeMargin(0, 0, 5, 0);
        badgeView.setBadgeCount(count);
    }

    @Override
    public void callBack(Object object) {
        switch (msgWhat) {
            case MSG.MSG_PRODUCT_DETAILS_SUCCESS: // 商品详情
                scoreMap = FastJsonUtil.getBean(object.toString(), "body", "scoreMap", ScoreMap.class);
                dataMallVO = FastJsonUtil.getBean(object.toString(), "body", "commodityInfo", DataMallVO.class);
                getEva();
                initBanner();
                isCollect();
                setContent();
                break;
            case MSG.MSG_FIND_PRODUCT_EVALUTION_LIST_SUCCESS: // 评论列表
                evaluateVOList = FastJsonUtil.getListBean(object.toString(), "body", "productEvaList", EvaluateVO.class);
                if (null == evaluateVOList || evaluateVOList.size() <= 0) { //无评论 则隐藏评论布局
                    viewLineEvaluate.setVisibility(View.GONE);
                    itemEvaluateLayout.setVisibility(View.GONE);
                } else {
                    viewLineEvaluate.setVisibility(View.VISIBLE);
                    itemEvaluateLayout.setVisibility(View.VISIBLE);
                    setItemEvaData(evaluateVOList);
                }
                break;
            case MSG.MSG_EVALUATION_TYPE_COUNT_SUCCESS: // 各评论个数
                String evaTypeCount = FastJsonUtil.getString(object.toString(), "productEvalateCounts");
                if (!StringUtil.isStrEmpty(evaTypeCount)) {
                    evaCountArray = evaTypeCount.split("\\|");
                    setEvaData(evaCountArray);
                }
                break;
        }

    }

    /**
     * 设置总评价数据
     *
     * @param evaCount
     */
    private void setEvaData(String[] evaCount) {
        if (evaCount.length <= 0) {
            dataDetailTvEvaluate.setText(String.format("评价（%s）", "0"));
            dataDetailTvGrade.setText(String.format("%s分", "0"));
            setStar("0");
        } else {
            dataDetailTvEvaluate.setText(String.format("评价（%s）", evaCount[1]));
            dataDetailTvGrade.setText(String.format("%s分", evaCount[0]));
            setStar(evaCount[0]);
        }
    }

    /**
     * 设置第一条评论数据
     *
     * @param evaluateVOList 评论集合
     */
    private void setItemEvaData(List<EvaluateVO> evaluateVOList) {
        if (evaluateVOList.get(0).getImage() != null)
            FrescoUtil.showImageSmall(evaluateVOList.get(0).getImage(), itemEvaluateSdvHead); // 评论者头像
        if (evaluateVOList.size() > 0) {
            if (evaluateVOList.get(0).isIsAnonymity()) // 匿名用户
                itemEvaluateTvName.setText("匿名用户");
            else
                itemEvaluateTvName.setText(evaluateVOList.get(0).getEvaluatePerson());
            itemEvaluateTvTime.setText(evaluateVOList.get(0).getEvaluateTime());
            itemEvaluateTvContent.setText(evaluateVOList.get(0).getContent());
            setItemStar(evaluateVOList.get(0).getScore());
        }
    }

    /**
     * 设置评论星数
     *
     * @param score
     */
    private void setStar(String score) {
        switch (score) {
            case "0.0":
                dataDetailIvStar1.setImageResource(R.drawable.icon_average_star_hollow);
                dataDetailIvStar2.setImageResource(R.drawable.icon_average_star_hollow);
                dataDetailIvStar3.setImageResource(R.drawable.icon_average_star_hollow);
                dataDetailIvStar4.setImageResource(R.drawable.icon_average_star_hollow);
                dataDetailIvStar5.setImageResource(R.drawable.icon_average_star_hollow);
                break;
            case "1.0":
                dataDetailIvStar1.setImageResource(R.drawable.icon_average_star_solid);
                dataDetailIvStar2.setImageResource(R.drawable.icon_average_star_hollow);
                dataDetailIvStar3.setImageResource(R.drawable.icon_average_star_hollow);
                dataDetailIvStar4.setImageResource(R.drawable.icon_average_star_hollow);
                dataDetailIvStar5.setImageResource(R.drawable.icon_average_star_hollow);
                break;
            case "2.0":
                dataDetailIvStar1.setImageResource(R.drawable.icon_average_star_solid);
                dataDetailIvStar2.setImageResource(R.drawable.icon_average_star_solid);
                dataDetailIvStar3.setImageResource(R.drawable.icon_average_star_hollow);
                dataDetailIvStar4.setImageResource(R.drawable.icon_average_star_hollow);
                dataDetailIvStar5.setImageResource(R.drawable.icon_average_star_hollow);
                break;
            case "3.0":
                dataDetailIvStar1.setImageResource(R.drawable.icon_average_star_solid);
                dataDetailIvStar2.setImageResource(R.drawable.icon_average_star_solid);
                dataDetailIvStar3.setImageResource(R.drawable.icon_average_star_solid);
                dataDetailIvStar4.setImageResource(R.drawable.icon_average_star_hollow);
                dataDetailIvStar5.setImageResource(R.drawable.icon_average_star_hollow);
                break;
            case "4.0":
                dataDetailIvStar1.setImageResource(R.drawable.icon_average_star_solid);
                dataDetailIvStar2.setImageResource(R.drawable.icon_average_star_solid);
                dataDetailIvStar3.setImageResource(R.drawable.icon_average_star_solid);
                dataDetailIvStar4.setImageResource(R.drawable.icon_average_star_solid);
                dataDetailIvStar5.setImageResource(R.drawable.icon_average_star_hollow);
                break;
            case "5.0":
                dataDetailIvStar1.setImageResource(R.drawable.icon_average_star_solid);
                dataDetailIvStar2.setImageResource(R.drawable.icon_average_star_solid);
                dataDetailIvStar3.setImageResource(R.drawable.icon_average_star_solid);
                dataDetailIvStar4.setImageResource(R.drawable.icon_average_star_solid);
                dataDetailIvStar5.setImageResource(R.drawable.icon_average_star_solid);
                break;
        }
    }

    /**
     * 设置评论星数
     *
     * @param score
     */
    private void setItemStar(int score) {
        switch (score) {
            case 1:
                itemEvaluateIvStar1.setImageResource(R.drawable.icon_average_star_solid);
                itemEvaluateIvStar2.setImageResource(R.drawable.icon_average_star_hollow);
                itemEvaluateIvStar3.setImageResource(R.drawable.icon_average_star_hollow);
                itemEvaluateIvStar4.setImageResource(R.drawable.icon_average_star_hollow);
                itemEvaluateIvStar5.setImageResource(R.drawable.icon_average_star_hollow);
                break;
            case 2:
                itemEvaluateIvStar1.setImageResource(R.drawable.icon_average_star_solid);
                itemEvaluateIvStar2.setImageResource(R.drawable.icon_average_star_solid);
                itemEvaluateIvStar3.setImageResource(R.drawable.icon_average_star_hollow);
                itemEvaluateIvStar4.setImageResource(R.drawable.icon_average_star_hollow);
                itemEvaluateIvStar5.setImageResource(R.drawable.icon_average_star_hollow);
                break;
            case 3:
                itemEvaluateIvStar1.setImageResource(R.drawable.icon_average_star_solid);
                itemEvaluateIvStar2.setImageResource(R.drawable.icon_average_star_solid);
                itemEvaluateIvStar3.setImageResource(R.drawable.icon_average_star_solid);
                itemEvaluateIvStar4.setImageResource(R.drawable.icon_average_star_hollow);
                itemEvaluateIvStar5.setImageResource(R.drawable.icon_average_star_hollow);
                break;
            case 4:
                itemEvaluateIvStar1.setImageResource(R.drawable.icon_average_star_solid);
                itemEvaluateIvStar2.setImageResource(R.drawable.icon_average_star_solid);
                itemEvaluateIvStar3.setImageResource(R.drawable.icon_average_star_solid);
                itemEvaluateIvStar4.setImageResource(R.drawable.icon_average_star_solid);
                itemEvaluateIvStar5.setImageResource(R.drawable.icon_average_star_hollow);
                break;
            case 5:
                itemEvaluateIvStar1.setImageResource(R.drawable.icon_average_star_solid);
                itemEvaluateIvStar2.setImageResource(R.drawable.icon_average_star_solid);
                itemEvaluateIvStar3.setImageResource(R.drawable.icon_average_star_solid);
                itemEvaluateIvStar4.setImageResource(R.drawable.icon_average_star_solid);
                itemEvaluateIvStar5.setImageResource(R.drawable.icon_average_star_solid);
                break;
        }
    }

    /**
     * 设置商户等级
     *
     * @param grade
     */
    private void setMerchantLevel(String grade) {
        switch (grade) {
            case "1.0":
                dataDetailIvLantern1.setVisibility(View.VISIBLE);
                dataDetailIvLantern2.setVisibility(View.INVISIBLE);
                dataDetailIvLantern3.setVisibility(View.INVISIBLE);
                dataDetailIvLantern4.setVisibility(View.INVISIBLE);
                dataDetailIvLantern5.setVisibility(View.INVISIBLE);
                break;
            case "2.0":
                dataDetailIvLantern1.setVisibility(View.VISIBLE);
                dataDetailIvLantern2.setVisibility(View.VISIBLE);
                dataDetailIvLantern3.setVisibility(View.INVISIBLE);
                dataDetailIvLantern4.setVisibility(View.INVISIBLE);
                dataDetailIvLantern5.setVisibility(View.INVISIBLE);
                break;
            case "3.0":
                dataDetailIvLantern1.setVisibility(View.VISIBLE);
                dataDetailIvLantern2.setVisibility(View.VISIBLE);
                dataDetailIvLantern3.setVisibility(View.VISIBLE);
                dataDetailIvLantern4.setVisibility(View.INVISIBLE);
                dataDetailIvLantern5.setVisibility(View.INVISIBLE);
                break;
            case "4.0":
                dataDetailIvLantern1.setVisibility(View.VISIBLE);
                dataDetailIvLantern2.setVisibility(View.VISIBLE);
                dataDetailIvLantern3.setVisibility(View.VISIBLE);
                dataDetailIvLantern4.setVisibility(View.VISIBLE);
                dataDetailIvLantern5.setVisibility(View.INVISIBLE);
                break;
            case "5.0":
                dataDetailIvLantern1.setVisibility(View.VISIBLE);
                dataDetailIvLantern2.setVisibility(View.VISIBLE);
                dataDetailIvLantern3.setVisibility(View.VISIBLE);
                dataDetailIvLantern4.setVisibility(View.VISIBLE);
                dataDetailIvLantern5.setVisibility(View.VISIBLE);
                break;
        }
    }

    //根据是否已收藏状态显示不同图片
    private void setCollectImg(String collected) {
        if (collected.equals("true")) {
            isCollected = true;
//            detailBottomIvCollect.setBackgroundResource(R.drawable.icon_collect_collected);
            detailBottomIvCollect.setImageResource(R.drawable.icon_collect_collected);
        } else {
            isCollected = false;
//            detailBottomIvCollect.setBackgroundResource(R.drawable.icon_collect_normal);
            detailBottomIvCollect.setImageResource(R.drawable.icon_collect_normal);
        }
    }

    @Override
    public void rightOnClick() {

    }


    @OnClick({R.id.detail_bottom_ll_collect, R.id.detail_bottom_ll_share, R.id.detail_bottom_ll_shop_cart, R.id.detail_bottom_tv_add_cart,
            R.id.detail_bottom_tv_buy_now, R.id.data_detail_ll_collect_merchants, R.id.data_detail_ll_goto_merchant_home,
            R.id.data_detail_rl_goods_summary, R.id.data_detail_rl_eva_list, R.id.data_detail_iv_chat})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.detail_bottom_ll_collect:
                if (isCollected) { //已收藏 取消收藏
                    cancelCollect();
                } else { // 没有收藏 收藏
                    collect();
                }
                break;
            case R.id.detail_bottom_ll_share:
                shareProduct();
                break;
            case R.id.detail_bottom_ll_shop_cart:
                GotoUtil.gotoActivity(this, CartActivity.class);
                break;
            case R.id.detail_bottom_tv_add_cart:
                addCart();
                break;
            case R.id.detail_bottom_tv_buy_now:
                GotoUtil.gotoActivity(this, ConfirmOrdersActivity.class, "DataMallVO", dataMallVO);
                break;
            case R.id.data_detail_ll_goto_merchant_home:
                GotoUtil.gotoActivity(this, MerchantActivity.class, "merchantId", dataMallVO.getMerchant().getId());
                break;
            case R.id.data_detail_ll_collect_merchants:
                if (isMerchantsCollected) {
                    showToast("已收藏");
                } else {
                    collectMerchants();
                }
                break;
            case R.id.data_detail_rl_goods_summary:
                GotoUtil.gotoActivity(this, ProductSummaryActivity.class, "productId", dataMallVO.getId());
                break;
            case R.id.data_detail_rl_eva_list:
                if (evaluateVOList == null || evaluateVOList.size() <= 0) // 没有评论 不跳转
                    return;
                GotoUtil.gotoActivity(this, EvaluateListActivity.class);
                break;
            case R.id.data_detail_iv_chat:
                if (null == dataMallVO || null == dataMallVO.getMerchant())
                    return;

                break;
        }
    }

    /**
     * 收藏店铺
     */
    private void collectMerchants() {
        //TODO dataMallVO.getMerchant().getHomePageImages() 暂时为空 店铺图片
        collectType = Constant.STORE_MERCHANTS;
        BusinessCollect.store(this, dataMallVO.getMerchant().getMerchantName(), "", Constant.STORE_MERCHANTS, dataMallVO.getMerchant().getId(),
                "", dataMallVO.getMerchant().getHeadPortrait(), "", StringUtil.jointString(URL.URL_SHOW_MERCHANT_HOME_COLLECT, dataMallVO.getMerchant().getId()), mHandler);
    }

    /**
     * 分享商品
     */
    private void shareProduct() {

        //标题
        String title = dataMallVO.getTitle();
        //简介
        String introduce = dataMallVO.getIntroduce();
        //展示图片
        String imagepath = dataMallVO.getImages();
        //链接地址
        String url = URL.URL_PRODUCT_DETAILS_COLLECT_URL + dataMallVO.getId() + "&renderType=" + Constant.RENDER_TYPE;

//        ShareUtil.showShare(this, title, introduce, url, imagepath);

    }

    /**
     * 取消收藏
     */
    private void cancelCollect() {
        BusinessCollect.cancelStore(this, dataMallVO.getId(), mHandler);
    }

    /**
     * 收藏
     */
    private void collect() {
        collectType = Constant.STORE_GOODS;
        BusinessCollect.store(this, dataMallVO.getTitle(), dataMallVO.getImages(), Constant.STORE_GOODS, dataMallVO.getId(), dataMallVO.getAmount_num(),
                "", dataMallVO.getIntroduce(), StringUtil.jointString(URL.URL_PRODUCT_DETAILS_COLLECT_URL, dataMallVO.getId()), mHandler);
    }

    /**
     * 加入购物车
     */
    private void addCart() {
        BusinessCart.addShoppingCartItem(this, dataMallVO.getId(), "1", dataMallVO.getAmount_num(),
                dataMallVO.getIntroduce(), dataMallVO.getMerchant().getId(),
                dataMallVO.getMerchant().getMerchantName(), dataMallVO.getMerchant().getHeadPortrait(), dataMallVO.getMerchant().getMobilePhone(), dataMallVO.getMerchant().getFullAddress(), mHandler);
    }

    /**
     * 获取购物车数量
     *
     * @return
     */
    public void getCartNum() {
        BusinessCart.getShoppingCartItemCount(this, mHandler);
    }

    /**
     * 是否已收藏
     */
    public void isCollect() {
        BusinessCollect.isCollectApi(this, dataMallVO.getId(), mHandler);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }
}
